home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / tex / ascutils.zip / CIPHER.ASM < prev    next >
Assembly Source File  |  1988-05-19  |  2KB  |  92 lines

  1. ;                    CIPHER
  2. ;
  3. codeseg        segment
  4.         assume    cs:codeseg, ds:codeseg
  5.         org    100h
  6. cipher        proc    far
  7.  
  8. start:
  9.         mov    si,081h            ; PSP command line buffer
  10. cipher_ck:
  11.         lodsb
  12.         cmp    al,020h
  13.         je    cipher_ck
  14.         dec    si
  15.         mov    di,si
  16.         mov    c_start,si        ; save start address
  17.         cmp    byte ptr [si],0Dh    ; error - no cipher string
  18.         jne    cipher_get
  19.  
  20.         mov    dx,offset errmsg    ; error message
  21.         mov    cx,01Ah
  22.         mov    bx,2            ; std error output
  23.         mov    ah,040h
  24.         int    021h
  25.     
  26. Exit:        int    020h            ; pgm terminate
  27.  
  28. cipher_get:
  29.         lodsb                ; measure cipher string
  30.         cmp    al,020h
  31.         je    cipher_len
  32.         cmp    al,0Dh
  33.         jne    cipher_get
  34. cipher_len:
  35.         dec    si
  36.         mov    c_end,si        ; point to end of cipher str
  37.         mov    byte ptr [si],0        ; null terminate string.
  38. Main:
  39.         cld
  40.         mov    dx,offset last_line    ; point to end of pgm block
  41.         mov    cx,1000h        ; arbitrary char count
  42.         mov    bx,0            ; std input
  43.         mov    ah,03Fh            ; input chars
  44.         int    021h
  45.     
  46.         mov    cx,ax        ; ax has actual input char count
  47.         jcxz    Exit        ; if it's 0, quit.
  48.         push    cx        ; save char count
  49.         mov    bx,di        ; save cipher offset in bx
  50.         mov    si,dx        ; point to buffer
  51.         mov    di,dx
  52.  
  53. cipher_loop:
  54.         cmp    bx,c_end    ; see if we've reached end of cipher
  55.         jne    cipher_it    ; no? do it!
  56.         mov    bx,c_start    ; if so, start again.
  57. cipher_it:
  58.         mov    dx,[bx]
  59.         mov    ax,6255h
  60.         mul    dx
  61.         add    ax,3619h
  62.         mov    [bx],ax        ; scramble cipher while we're at it
  63.         inc    bx
  64.         mov    dl,al        ; remainder of the arithmetic
  65.         lodsb
  66.         xor    al,dl        ; this encodes the character
  67.         stosb            ; and saves it (same address)
  68.         loop    cipher_loop    ; continue for cx chars
  69.  
  70.         mov    di,bx        ; save bx
  71.         pop    cx        ; get saved char count
  72.         mov    dx,offset last_line    ; set up dx for output
  73.         mov    bx,1            ; std out
  74.         mov    ah,40h            ; output cx chars to std out
  75.         int    21h
  76.     
  77.         jmp    short Main    ; get more input.
  78.  
  79. c_start        dw    81h        ; cipher string storage - initialized
  80. c_end        dw    81h        ; to PSP command line buffer.
  81.  
  82. errmsg        db    'Must specify a code word', 0Dh, 0Ah
  83.  
  84. last_line:    db    0        ; marks last line of program.
  85.  
  86. cipher        endp
  87.  
  88. codeseg        ends
  89.  
  90.         end    start
  91.  
  92.